import numpy as np
import matplotlib.pyplot as plt
import cv2
def nothing(x):
    pass
img = cv2.imread('./img/plant.jpg')
cv2.imshow('image_o',img)
print('img info:')
print('shape:',img.shape,' pixal num:',img.size,' dtype:',img.dtype)
zeros = np.zeros(img.shape[:2], dtype = "uint8")
#RGB拆分
#b,g,r=cv2.split(img)
#RGB组合br
#img2=cv2.merge([b,g,r])
b = img[:,:,0]
g = img[:,:,1]
r = img[:,:,2]
ratio=0.0
cv2.namedWindow('image')
cv2.createTrackbar('Ratio','image',0,255,nothing)
while(1):
    cv2.imshow('image',(r*(ratio/255.0))/(b+g+r))
    k=cv2.waitKey(1)&0xFF
    if k==27:
        break
    ratio=cv2.getTrackbarPos('Ratio','image')
    #print((1-ratio/255.0))
cv2.destroyAllWindows()